// pages/receiptDetail/receiptDetail.js
const http = require('../../utils/http.js');
const app = getApp();
var regeneratorRuntime = require("../../utils/regenerator-runtime/runtime-module.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    grabHidden:true
  },

//抢单
  grabOrder(){
    var uid = app.globalData.uid;
    var oid = this.data.oid;
    console.log(uid)
    http.fetchApi('procedure_t', {p: 'R2002001|'+uid+'|'+oid}).then(res=>{
      if(res.data.code==1){
        var codes = res.data.results[0].codes;
        this.setData({
          codes
        })
        this.setData({
          grabHidden: false
        })
        console.log(codes)
        if(codes==1){
          //抢单成功
      
        }
      }else{
        http.showToast('获取用户信息失败!' + '', '', 'none')
      }
    })

  },
  cancel(){
    this.setData({
      grabHidden: true
    })
  },
  confirm(){
    var codes=this.data.codes;
    if(codes==1){
      //抢单成功点击确定
      wx.reLaunch({
        url: '../index/index'
      })
    }else{
      this.setData({
        grabHidden: true
      })
    }
   
  },

  //获取闪送订单
  getShansong(){
    var oid = this.data.oid;
    http.fetchApi('procedure_t', { p: `R2002009|${oid}`}).then(res=>{
      if(res.data.code==1){
        var jiadanArr = res.data.results;
        console.log(jiadanArr);
        this.setData({
          jiadanArr
        })
      }
    })
  },

  //获取订单详情
  getOrderDetails(){
    var oid=this.data.oid;
    http.fetchApi('procedure_t', { p: 'R2002002|' + oid }).then(res=>{
      if(res.data.code==1){
        var orderDetail = res.data.results[0];
        console.log(orderDetail)
        this.setData({
          orderDetail
        })
      }else{
        http.showToast('获取数据失败!' + '', '', 'none')
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var oid = options.oid;
    this.setData({
      oid
    })

    this.getOrderDetails();
    this.getShansong();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})